package com.easytopit.demo.spring.mvc.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.easytopit.demo.spring.mvc.domain.User;
import com.easytopit.demo.spring.mvc.domain.UserPara;

@RestController
public class AjaxController {

	@RequestMapping(value = "/search/api/")
	public List<User> getSearchResultViaAjax(@RequestBody UserPara userPara) {
		// 每页数据
		int pageSize = userPara.getPageSize() == null ? 3 : userPara.getPageSize();
		// 发回数据
		ArrayList<User> users = new ArrayList<>();
		for (int i = 0; i < pageSize; i++) {
			User user = new User();
			user.setId(i);
			user.setName("i"+i);
			users.add(user);
		}
		// 返回的数据
		return users;

	}
	
}